<template><div><p>本文档最新版为 <a href="https://learnku.com/docs/laravel/10.x" target="_blank" rel="noopener noreferrer">10.x</a>，旧版本可能放弃维护，推荐阅读最新版！</p>
<h2 id="升级指南" tabindex="-1"><a class="header-anchor" href="#升级指南"><span>升级指南</span></a></h2>
<ul>
<li><a href="#upgrade-11.0">从 10.x 升级到 11.0</a></li>
</ul>
<h2 id="高影响变化" tabindex="-1"><a class="header-anchor" href="#高影响变化"><span>高影响变化</span></a></h2>
<ul>
<li><a href="#updating-dependencies">更新依赖</a></li>
<li><a href="#application-structure">应用结构</a></li>
<li><a href="#floating-point-types">浮点数类型</a></li>
<li><a href="#modifying-columns">修改列</a></li>
<li><a href="#sqlite-minimum-version">SQLite 最低版本</a></li>
<li><a href="#updating-sanctum">升级 Sanctum</a></li>
</ul>
<h2 id="中等影响变化" tabindex="-1"><a class="header-anchor" href="#中等影响变化"><span>中等影响变化</span></a></h2>
<ul>
<li><a href="#carbon-3">Carbon 3</a></li>
<li><a href="#password-rehashing">密码再处理</a></li>
<li><a href="#per-second-rate-limiting">每秒请求限流</a></li>
</ul>
<h2 id="较小影响变化" tabindex="-1"><a class="header-anchor" href="#较小影响变化"><span>较小影响变化</span></a></h2>
<ul>
<li><a href="#doctrine-dbal-removal">Doctrine DBAL 移除</a></li>
<li><a href="#eloquent-model-casts-method">Eloquent 模型 <code v-pre>casts</code> 方法</a></li>
<li><a href="#spatial-types">空间类型</a></li>
<li><a href="#spatie-once-package">Spatie Once 包</a></li>
<li><a href="#the-enumerable-contract"><code v-pre>Enumerable</code> 契约</a></li>
<li><a href="#the-user-provider-contract"><code v-pre>UserProvider</code> 契约</a></li>
<li><a href="#the-authenticatable-contract"><code v-pre>Authenticatable</code> 契约</a></li>
</ul>
<h2 id="从-10-x-升级到-11-0" tabindex="-1"><a class="header-anchor" href="#从-10-x-升级到-11-0"><span>从 10.x 升级到 11.0</span></a></h2>
<h4 id="预计升级时间-15-分钟" tabindex="-1"><a class="header-anchor" href="#预计升级时间-15-分钟"><span>预计升级时间：15 分钟</span></a></h4>
<blockquote>
<p>[!注意]<br>
我们试图记录每一个可能的破坏性变更。由于其中一些破坏性变更位于框架的底层部分，因此只有其中一部分变更实际上会影响你的应用程序。想节省时间吗？你可以使用 <a href="https://laravelshift.com/" target="_blank" rel="noopener noreferrer">Laravel Shift</a> 来帮助自动升级你的应用程序。</p>
</blockquote>
<h3 id="更新依赖项" tabindex="-1"><a class="header-anchor" href="#更新依赖项"><span>更新依赖项</span></a></h3>
<p><strong>影响可能性：高</strong></p>
<h4 id="要求php-8-2-0" tabindex="-1"><a class="header-anchor" href="#要求php-8-2-0"><span>要求PHP 8.2.0</span></a></h4>
<p>Laravel 当前要求 PHP 8.2.0 或更高版本。</p>
<h4 id="要求curl-7-34-0" tabindex="-1"><a class="header-anchor" href="#要求curl-7-34-0"><span>要求curl 7.34.0</span></a></h4>
<p>Laravel 的 HTTP 客户端要求 curl 7.34.0 或更高版本。</p>
<h4 id="composer-依赖项" tabindex="-1"><a class="header-anchor" href="#composer-依赖项"><span>Composer 依赖项</span></a></h4>
<p>你应该在应用程序的 <code v-pre>composer.json</code> 文件中更新以下依赖项：</p>
<ul>
<li><code v-pre>laravel/framework</code> 更新到 <code v-pre>^11.0</code></li>
<li><code v-pre>nunomaduro/collision</code> 更新到 <code v-pre>^8.1</code></li>
<li><code v-pre>laravel/breeze</code> 更新到 <code v-pre>^2.0</code> (若安装此依赖)</li>
<li><code v-pre>laravel/cashier</code> 更新到 <code v-pre>^15.0</code> (若安装此依赖)</li>
<li><code v-pre>laravel/dusk</code> 更新到 <code v-pre>^8.0</code> (若安装此依赖)</li>
<li><code v-pre>laravel/jetstream</code> 更新到 <code v-pre>^5.0</code> (若安装此依赖)</li>
<li><code v-pre>laravel/octane</code> 更新到 <code v-pre>^2.3</code> (若安装此依赖)</li>
<li><code v-pre>laravel/passport</code> 更新到 <code v-pre>^12.0</code> (若安装此依赖)</li>
<li><code v-pre>laravel/sanctum</code> 更新到 <code v-pre>^4.0</code> (若安装此依赖)</li>
<li><code v-pre>laravel/scout</code> 更新到 <code v-pre>^10.0</code> (若安装此依赖)</li>
<li><code v-pre>laravel/spark-stripe</code> 更新到 <code v-pre>^5.0</code> (若安装此依赖)</li>
<li><code v-pre>laravel/telescope</code> 更新到 <code v-pre>^5.0</code> (若安装此依赖)</li>
<li><code v-pre>inertiajs/inertia-laravel</code> 更新到 <code v-pre>^1.0</code> (若安装此依赖)</li>
</ul>
<p>如果你的应用程序使用了 Laravel Cashier Stripe、Passport、Sanctum、Spark Stripe 或 Telescope，你需要将它们的迁移文件发布到你的应用程序中。Cashier Stripe、Passport、Sanctum、Spark Stripe 和 Telescope <strong>不再自动从它们自己的迁移目录加载迁移文件</strong>。因此，你应该运行以下命令将它们的迁移文件发布到你的应用程序：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan vendor:publish <span class="token parameter variable">--tag</span><span class="token operator">=</span>cashier-migrations</span>
<span class="line">php artisan vendor:publish <span class="token parameter variable">--tag</span><span class="token operator">=</span>passport-migrations</span>
<span class="line">php artisan vendor:publish <span class="token parameter variable">--tag</span><span class="token operator">=</span>sanctum-migrations</span>
<span class="line">php artisan vendor:publish <span class="token parameter variable">--tag</span><span class="token operator">=</span>spark-migrations</span>
<span class="line">php artisan vendor:publish <span class="token parameter variable">--tag</span><span class="token operator">=</span>telescope-migrations</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>此外，你应该查看这些包的升级指南，以确保你了解任何其他的重大变更：</p>
<ul>
<li><a href="#cashier-stripe">Laravel Cashier Stripe</a></li>
<li><a href="#passport">Laravel Passport</a></li>
<li><a href="#sanctum">Laravel Sanctum</a></li>
<li><a href="#spark-stripe">Laravel Spark Stripe</a></li>
<li><a href="#telescope">Laravel Telescope</a></li>
</ul>
<p>如果你已手动安装了 Laravel 安装器，你应该通过 Composer 更新安装器：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token function">composer</span> global require laravel/installer:^5.6</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>最后，如果你之前已将 <code v-pre>doctrine/dbal</code> Composer 依赖项添加到你的应用程序，你可以将其移除，因为 Laravel 不再依赖这个包。</p>
<h3 id="应用程序结构" tabindex="-1"><a class="header-anchor" href="#应用程序结构"><span>应用程序结构</span></a></h3>
<p>Laravel 11 引入了一种新的默认应用程序结构，包含更少的默认文件。具体来说，新的 Laravel 应用程序包含更少的服务提供者、中间件和配置文件。</p>
<p>然而，我们<strong>不推荐</strong>从 Laravel 10 升级到 Laravel 11 的应用程序尝试迁移它们的应用程序结构，因为 Laravel 11 已经精心调整以支持 Laravel 10 的应用程序结构。</p>
<h3 id="认证" tabindex="-1"><a class="header-anchor" href="#认证"><span>认证</span></a></h3>
<h4 id="密码重哈希" tabindex="-1"><a class="header-anchor" href="#密码重哈希"><span>密码重哈希</span></a></h4>
<p>如果自密码最后一次哈希以来你的哈希算法的“工作因子”已更新，Laravel 11 将在认证过程中自动重新哈希你用户的密码。</p>
<p>通常情况下，这不应该影响你的应用程序；然而，你可以通过在应用程序的 <code v-pre>config/hashing.php</code> 配置文件中添加 <code v-pre>rehash_on_login</code> 选项来禁用此行为：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'rehash_on_login'</span> <span class="token operator">=></span> <span class="token constant boolean">false</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h4 id="userprovider-合约" tabindex="-1"><a class="header-anchor" href="#userprovider-合约"><span><code v-pre>UserProvider</code> 合约</span></a></h4>
<p><strong>影响可能性：低</strong></p>
<p><code v-pre>Illuminate\Contracts\Auth\UserProvider</code> 合约新增了一个 <code v-pre>rehashPasswordIfRequired</code> 方法。该方法负责在应用程序的哈希算法工作因子发生变化时，重新哈希并存储用户的密码。</p>
<p>如果你的应用程序或包定义了一个实现此接口的类，你应该在你的实现中添加新的 <code v-pre>rehashPasswordIfRequired</code> 方法。你可以在 <code v-pre>Illuminate\Auth\EloquentUserProvider</code> 类中找到一个参考实现：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">rehashPasswordIfRequired</span><span class="token punctuation">(</span><span class="token class-name type-declaration">Authenticatable</span> <span class="token variable">$user</span><span class="token punctuation">,</span> <span class="token keyword type-hint">array</span> <span class="token variable">$credentials</span><span class="token punctuation">,</span> <span class="token keyword type-hint">bool</span> <span class="token variable">$force</span> <span class="token operator">=</span> <span class="token constant boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h4 id="authenticatable-合约" tabindex="-1"><a class="header-anchor" href="#authenticatable-合约"><span><code v-pre>Authenticatable</code> 合约</span></a></h4>
<p><strong>影响可能性：低</strong></p>
<p><code v-pre>Illuminate\Contracts\Auth\Authenticatable</code> 合约新增了一个 <code v-pre>getAuthPasswordName</code> 方法。该方法负责返回你的认证实体的密码列的名称。</p>
<p>如果你的应用程序或包定义了一个实现此接口的类，你应该在你的实现中添加新的 <code v-pre>getAuthPasswordName</code> 方法：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">getAuthPasswordName</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">return</span> <span class="token string single-quoted-string">'password'</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Laravel 自带的默认 <code v-pre>User</code> 模型自动获得此方法，因为该方法包含在 <code v-pre>Illuminate\Auth\Authenticatable</code> 特性中。</p>
<h4 id="authenticationexception-类" tabindex="-1"><a class="header-anchor" href="#authenticationexception-类"><span><code v-pre>AuthenticationException</code> 类</span></a></h4>
<p><strong>影响可能性：非常低</strong></p>
<p><code v-pre>Illuminate\Auth\AuthenticationException</code> 类的 <code v-pre>redirectTo</code> 方法现在要求其第一个参数为 <code v-pre>Illuminate\Http\Request</code> 实例。如果你在手动捕获此异常并调用 <code v-pre>redirectTo</code> 方法，你应该相应地更新你的代码：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$e</span> <span class="token keyword">instanceof</span> <span class="token class-name">AuthenticationException</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$path</span> <span class="token operator">=</span> <span class="token variable">$e</span><span class="token operator">-></span><span class="token function">redirectTo</span><span class="token punctuation">(</span><span class="token variable">$request</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="缓存" tabindex="-1"><a class="header-anchor" href="#缓存"><span>缓存</span></a></h3>
<h4 id="缓存键前缀" tabindex="-1"><a class="header-anchor" href="#缓存键前缀"><span>缓存键前缀</span></a></h4>
<p><strong>影响可能性：非常低</strong></p>
<p>以前，如果为 DynamoDB、Memcached 或 Redis 缓存存储定义了缓存键前缀，Laravel 会在前缀后添加一个 <code v-pre>:</code>。在 Laravel 11 中，缓存键前缀不再添加 <code v-pre>:</code> 后缀。如果你想保持之前的前缀行为，你可以手动在你的缓存键前缀中添加 <code v-pre>:</code> 后缀。</p>
<h3 id="集合" tabindex="-1"><a class="header-anchor" href="#集合"><span>集合</span></a></h3>
<h4 id="enumerable-合约" tabindex="-1"><a class="header-anchor" href="#enumerable-合约"><span><code v-pre>Enumerable</code> 合约</span></a></h4>
<p><strong>影响可能性：低</strong></p>
<p><code v-pre>Illuminate\Support\Enumerable</code> 合约的 <code v-pre>dump</code> 方法已更新，以接受一个可变参数 <code v-pre>...$args</code>。如果你正在实现这个接口，你应该相应地更新你的实现：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">dump</span><span class="token punctuation">(</span><span class="token operator">...</span><span class="token variable">$args</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="数据库" tabindex="-1"><a class="header-anchor" href="#数据库"><span>数据库</span></a></h3>
<h4 id="sqlite-3-35-0" tabindex="-1"><a class="header-anchor" href="#sqlite-3-35-0"><span>SQLite 3.35.0+</span></a></h4>
<p><strong>影响可能性：高</strong></p>
<p>如果你的应用程序正在使用 SQLite 数据库，需要 SQLite 3.35.0 或更高版本。</p>
<h4 id="eloquent-模型-casts-方法" tabindex="-1"><a class="header-anchor" href="#eloquent-模型-casts-方法"><span>Eloquent 模型 <code v-pre>casts</code> 方法</span></a></h4>
<p><strong>影响可能性：低</strong></p>
<p>基础 Eloquent 模型类现在定义了一个 <code v-pre>casts</code> 方法，以支持属性转换的定义。如果你的应用程序中的某个模型正在定义一个 <code v-pre>casts</code> 关系，它可能与现在基础 Eloquent 模型类上存在的 <code v-pre>casts</code> 方法冲突。</p>
<h4 id="修改列" tabindex="-1"><a class="header-anchor" href="#修改列"><span>修改列</span></a></h4>
<p><strong>影响可能性：高</strong></p>
<p>在修改列时，你现在必须明确包括你想在列定义更改后保留的所有修饰符。任何缺失的属性都将被丢弃。例如，要保留 <code v-pre>unsigned</code>、<code v-pre>default</code> 和 <code v-pre>comment</code> 属性，即使这些属性已由之前的迁移分配给该列，你也必须在更改列时显式调用每个修饰符。</p>
<p>例如，假设你有一个迁移，它创建了一个带有 <code v-pre>unsigned</code>、<code v-pre>default</code> 和 <code v-pre>comment</code> 属性的 <code v-pre>votes</code> 列：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token class-name static-context">Schema</span><span class="token operator">::</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'users'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">Blueprint</span> <span class="token variable">$table</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$table</span><span class="token operator">-></span><span class="token function">integer</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'votes'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">unsigned</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">default</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">comment</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'投票数'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>后来，你编写了一个迁移，将该列更改为同时可为空：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token class-name static-context">Schema</span><span class="token operator">::</span><span class="token function">table</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'users'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">Blueprint</span> <span class="token variable">$table</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$table</span><span class="token operator">-></span><span class="token function">integer</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'votes'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">nullable</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">change</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>在 Laravel 10 中，这个迁移将保留列上的 <code v-pre>unsigned</code>、<code v-pre>default</code> 和 <code v-pre>comment</code> 属性。然而，在 Laravel 11 中，迁移现在必须也包括之前在列上定义的所有属性。否则，这些属性将被丢弃：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token class-name static-context">Schema</span><span class="token operator">::</span><span class="token function">table</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'users'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">Blueprint</span> <span class="token variable">$table</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$table</span><span class="token operator">-></span><span class="token function">integer</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'votes'</span><span class="token punctuation">)</span></span>
<span class="line">        <span class="token operator">-></span><span class="token function">unsigned</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">        <span class="token operator">-></span><span class="token function">default</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span></span>
<span class="line">        <span class="token operator">-></span><span class="token function">comment</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'投票数'</span><span class="token punctuation">)</span></span>
<span class="line">        <span class="token operator">-></span><span class="token function">nullable</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">        <span class="token operator">-></span><span class="token function">change</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p><code v-pre>change</code> 方法不会改变列的索引。因此，你可以使用索引修饰符在修改列时显式添加或删除索引：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token comment">// 添加索引...</span></span>
<span class="line"><span class="token variable">$table</span><span class="token operator">-></span><span class="token function">bigIncrements</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'id'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">primary</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">change</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// 删除索引...</span></span>
<span class="line"><span class="token variable">$table</span><span class="token operator">-></span><span class="token function">char</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'postal_code'</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">unique</span><span class="token punctuation">(</span><span class="token constant boolean">false</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">change</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>如果你不想更新应用程序中所有现有的“change”迁移以保留列的现有属性，你可以简单地<a href="https://learnku.com/docs/laravel/11.x/migrations#squashing-migrations" target="_blank" rel="noopener noreferrer">压缩你的迁移</a>：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan schema:dump</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>一旦你的迁移被压缩，Laravel 将使用你的应用程序的架构文件“迁移”数据库，然后运行任何待处理的迁移。</p>
<h4 id="浮点类型" tabindex="-1"><a class="header-anchor" href="#浮点类型"><span>浮点类型</span></a></h4>
<p><strong>影响可能性：高</strong></p>
<p><code v-pre>double</code> 和 <code v-pre>float</code> 迁移列类型已被重写，以确保在所有数据库中的一致性。</p>
<p><code v-pre>double</code> 列类型现在创建一个不带总位数和小数位（小数点后的数字）的 <code v-pre>DOUBLE</code> 等效列，这是标准的 SQL 语法。因此，你可以移除 <code v-pre>$total</code> 和 <code v-pre>$places</code> 参数：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$table</span><span class="token operator">-></span><span class="token function">double</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'amount'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p><code v-pre>float</code> 列类型现在创建一个不带总位数和小数位（小数点后的数字）的 <code v-pre>FLOAT</code> 等效列，但可以选择性地指定 <code v-pre>$precision</code> 来决定存储大小，作为一个 4 字节的单精度列或一个 8 字节的双精度列。因此，你可以移除 <code v-pre>$total</code> 和 <code v-pre>$places</code> 参数，并根据你的数据库文档指定你希望的 <code v-pre>$precision</code> 值：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$table</span><span class="token operator">-></span><span class="token keyword type-declaration">float</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'amount'</span><span class="token punctuation">,</span> <span class="token argument-name">precision</span><span class="token punctuation">:</span> <span class="token number">53</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p><code v-pre>unsignedDecimal</code>、<code v-pre>unsignedDouble</code> 和 <code v-pre>unsignedFloat</code> 方法已被移除，因为这些列类型的无符号修饰符已被 MySQL 弃用，并且从未在其他数据库系统中标准化。然而，如果你希望继续使用这些列类型的已弃用无符号属性，你可以将 <code v-pre>unsigned</code> 方法链接到列的定义上：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$table</span><span class="token operator">-></span><span class="token function">decimal</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'amount'</span><span class="token punctuation">,</span> <span class="token argument-name">total</span><span class="token punctuation">:</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token argument-name">places</span><span class="token punctuation">:</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">unsigned</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token variable">$table</span><span class="token operator">-></span><span class="token function">double</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'amount'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">unsigned</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token variable">$table</span><span class="token operator">-></span><span class="token keyword type-declaration">float</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'amount'</span><span class="token punctuation">,</span> <span class="token argument-name">precision</span><span class="token punctuation">:</span> <span class="token number">53</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">unsigned</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="专用-mariadb-驱动" tabindex="-1"><a class="header-anchor" href="#专用-mariadb-驱动"><span>专用 MariaDB 驱动</span></a></h4>
<p><strong>影响可能性：非常低</strong></p>
<p>Laravel 11 不再总是在连接到 MariaDB 数据库时使用 MySQL 驱动，而是添加了一个专用的 MariaDB 数据库驱动。</p>
<p>如果你的应用程序连接到 MariaDB 数据库，你可以更新连接配置为新的 <code v-pre>mariadb</code> 驱动，以便在将来从 MariaDB 的特定功能中获益：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'driver'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'mariadb'</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token string single-quoted-string">'url'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'DB_URL'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token string single-quoted-string">'host'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'DB_HOST'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'127.0.0.1'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token string single-quoted-string">'port'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'DB_PORT'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'3306'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token comment">// ...</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>目前，新的 MariaDB 驱动的行为与当前的 MySQL 驱动类似，但有一个例外：<code v-pre>uuid</code> 架构构建方法会创建原生 UUID 列而不是 <code v-pre>char(36)</code> 列。</p>
<p>如果你现有的迁移使用了 <code v-pre>uuid</code> 架构构建方法，并且你选择使用新的 <code v-pre>mariadb</code> 数据库驱动，你应该将迁移中调用 <code v-pre>uuid</code> 方法的地方更新为 <code v-pre>char</code>，以避免破坏性更改或意外行为：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token class-name static-context">Schema</span><span class="token operator">::</span><span class="token function">table</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'users'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">Blueprint</span> <span class="token variable">$table</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$table</span><span class="token operator">-></span><span class="token function">char</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'uuid'</span><span class="token punctuation">,</span> <span class="token number">36</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token comment">// ...</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="空间类型" tabindex="-1"><a class="header-anchor" href="#空间类型"><span>空间类型</span></a></h4>
<p><strong>影响可能性：低</strong></p>
<p>数据库迁移的空间列类型已被重写，以确保在所有数据库中的一致性。因此，你可以从你的迁移中移除 <code v-pre>point</code>、<code v-pre>lineString</code>、<code v-pre>polygon</code>、<code v-pre>geometryCollection</code>、<code v-pre>multiPoint</code>、<code v-pre>multiLineString</code>、<code v-pre>multiPolygon</code> 和 <code v-pre>multiPolygonZ</code> 方法，改用 <code v-pre>geometry</code> 或 <code v-pre>geography</code> 方法：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$table</span><span class="token operator">-></span><span class="token function">geometry</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'shapes'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token variable">$table</span><span class="token operator">-></span><span class="token function">geography</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'coordinates'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div></div></div><p>为了在 MySQL、MariaDB 和 PostgreSQL 上明确限制存储在列中的值的类型或空间参考系统标识符，你可以将 <code v-pre>subtype</code> 和 <code v-pre>srid</code> 传递给方法：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$table</span><span class="token operator">-></span><span class="token function">geometry</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'dimension'</span><span class="token punctuation">,</span> <span class="token argument-name">subtype</span><span class="token punctuation">:</span> <span class="token string single-quoted-string">'polygon'</span><span class="token punctuation">,</span> <span class="token argument-name">srid</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token variable">$table</span><span class="token operator">-></span><span class="token function">geography</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'latitude'</span><span class="token punctuation">,</span> <span class="token argument-name">subtype</span><span class="token punctuation">:</span> <span class="token string single-quoted-string">'point'</span><span class="token punctuation">,</span> <span class="token argument-name">srid</span><span class="token punctuation">:</span> <span class="token number">4326</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div></div></div><p>PostgreSQL 语法的 <code v-pre>isGeometry</code> 和 <code v-pre>projection</code> 列修饰符已相应地被移除。</p>
<h4 id="doctrine-dbal-移除" tabindex="-1"><a class="header-anchor" href="#doctrine-dbal-移除"><span>Doctrine DBAL 移除</span></a></h4>
<p><strong>影响可能性：低</strong></p>
<p>以下列出的 Doctrine DBAL 相关类和方法已被移除。Laravel 不再依赖此包，且注册自定义 Doctrine 类型对于正确创建和修改之前需要自定义类型的各种列类型不再必要：</p>
<ul>
<li><code v-pre>Illuminate\Database\Schema\Builder::$alwaysUsesNativeSchemaOperationsIfPossible</code> 类属性</li>
<li><code v-pre>Illuminate\Database\Schema\Builder::useNativeSchemaOperationsIfPossible()</code> 方法</li>
<li><code v-pre>Illuminate\Database\Connection::usingNativeSchemaOperations()</code> 方法</li>
<li><code v-pre>Illuminate\Database\Connection::isDoctrineAvailable()</code> 方法</li>
<li><code v-pre>Illuminate\Database\Connection::getDoctrineConnection()</code> 方法</li>
<li><code v-pre>Illuminate\Database\Connection::getDoctrineSchemaManager()</code> 方法</li>
<li><code v-pre>Illuminate\Database\Connection::getDoctrineColumn()</code> 方法</li>
<li><code v-pre>Illuminate\Database\Connection::registerDoctrineType()</code> 方法</li>
<li><code v-pre>Illuminate\Database\DatabaseManager::registerDoctrineType()</code> 方法</li>
<li><code v-pre>Illuminate\Database\PDO</code> 目录</li>
<li><code v-pre>Illuminate\Database\DBAL\TimestampType</code> 类</li>
<li><code v-pre>Illuminate\Database\Schema\Grammars\ChangeColumn</code> 类</li>
<li><code v-pre>Illuminate\Database\Schema\Grammars\RenameColumn</code> 类</li>
<li><code v-pre>Illuminate\Database\Schema\Grammars\Grammar::getDoctrineTableDiff()</code> 方法</li>
</ul>
<p>此外，通过应用程序的 <code v-pre>database</code> 配置文件中的 <code v-pre>dbal.types</code> 注册自定义 Doctrine 类型已不再需要。</p>
<p>如果你之前使用 Doctrine DBAL 来检查你的数据库及其关联表，你可以改用 Laravel 的新的原生架构方法（<code v-pre>Schema::getTables()</code>、<code v-pre>Schema::getColumns()</code>、<code v-pre>Schema::getIndexes()</code>、<code v-pre>Schema::getForeignKeys()</code> 等）。</p>
<h4 id="已废弃的架构方法" tabindex="-1"><a class="header-anchor" href="#已废弃的架构方法"><span>已废弃的架构方法</span></a></h4>
<p><strong>影响可能性：非常低</strong></p>
<p>基于 Doctrine 的已废弃方法 <code v-pre>Schema::getAllTables()</code>、<code v-pre>Schema::getAllViews()</code> 和 <code v-pre>Schema::getAllTypes()</code> 已被移除，取而代之的是新的 Laravel 原生方法 <code v-pre>Schema::getTables()</code>、<code v-pre>Schema::getViews()</code> 和 <code v-pre>Schema::getTypes()</code>。</p>
<p>在使用 PostgreSQL 和 SQL Server 时，新的架构方法不会接受三部分引用（例如 <code v-pre>database.schema.table</code>）。因此，你应该使用 <code v-pre>connection()</code> 来声明数据库：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token class-name static-context">Schema</span><span class="token operator">::</span><span class="token function">connection</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'database'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">hasTable</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'schema.table'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h4 id="架构构建器-getcolumntype-方法" tabindex="-1"><a class="header-anchor" href="#架构构建器-getcolumntype-方法"><span>架构构建器 <code v-pre>getColumnType()</code> 方法</span></a></h4>
<p><strong>影响可能性：非常低</strong></p>
<p><code v-pre>Schema::getColumnType()</code> 方法现在始终返回给定列的实际类型，而不是 Doctrine DBAL 等效类型。</p>
<h4 id="数据库连接接口" tabindex="-1"><a class="header-anchor" href="#数据库连接接口"><span>数据库连接接口</span></a></h4>
<p><strong>影响可能性：非常低</strong></p>
<p><code v-pre>Illuminate\Database\ConnectionInterface</code> 接口新增了一个 <code v-pre>scalar</code> 方法。如果你正在定义自己的该接口实现，你应该在你的实现中添加 <code v-pre>scalar</code> 方法：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">scalar</span><span class="token punctuation">(</span><span class="token variable">$query</span><span class="token punctuation">,</span> <span class="token variable">$bindings</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token variable">$useReadPdo</span> <span class="token operator">=</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="日期" tabindex="-1"><a class="header-anchor" href="#日期"><span>日期</span></a></h3>
<h4 id="carbon-3" tabindex="-1"><a class="header-anchor" href="#carbon-3"><span>Carbon 3</span></a></h4>
<p><strong>影响可能性：中等</strong></p>
<p>Laravel 11 支持 Carbon 2 和 Carbon 3。Carbon 是一个广泛用于 Laravel 及其生态系统中的包的日期操作库。如果你升级到 Carbon 3，请注意 <code v-pre>diffIn*</code> 方法现在返回浮点数，并且可能返回负值以指示时间方向，这与 Carbon 2 的行为有显著不同。查看 Carbon 的<a href="https://github.com/briannesbitt/Carbon/releases/tag/3.0.0" target="_blank" rel="noopener noreferrer">变更日志</a>以获取如何处理这些及其他变更的详细信息。</p>
<h3 id="邮件" tabindex="-1"><a class="header-anchor" href="#邮件"><span>邮件</span></a></h3>
<h4 id="mailer-合约" tabindex="-1"><a class="header-anchor" href="#mailer-合约"><span><code v-pre>Mailer</code> 合约</span></a></h4>
<p><strong>影响可能性：非常低</strong></p>
<p><code v-pre>Illuminate\Contracts\Mail\Mailer</code> 合约新增了一个 <code v-pre>sendNow</code> 方法。如果你的应用程序或包手动实现了这个合约，你应该在你的实现中添加新的 <code v-pre>sendNow</code> 方法：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">sendNow</span><span class="token punctuation">(</span><span class="token variable">$mailable</span><span class="token punctuation">,</span> <span class="token keyword type-hint">array</span> <span class="token variable">$data</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token variable">$callback</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="包" tabindex="-1"><a class="header-anchor" href="#包"><span>包</span></a></h3>
<h4 id="将服务提供者发布到应用程序" tabindex="-1"><a class="header-anchor" href="#将服务提供者发布到应用程序"><span>将服务提供者发布到应用程序</span></a></h4>
<p><strong>影响可能性：非常低</strong></p>
<p>如果你编写了一个 Laravel 包，该包手动将服务提供者发布到应用程序的 <code v-pre>app/Providers</code> 目录，并手动修改应用程序的 <code v-pre>config/app.php</code> 配置文件来注册服务提供者，你应该更新你的包以使用新的 <code v-pre>ServiceProvider::addProviderToBootstrapFile</code> 方法。</p>
<p><code v-pre>addProviderToBootstrapFile</code> 方法将自动将你发布的服务提供者添加到应用程序的 <code v-pre>bootstrap/providers.php</code> 文件中，因为在新的 Laravel 11 应用程序中 <code v-pre>config/app.php</code> 配置文件内不存在 <code v-pre>providers</code> 数组。</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>ServiceProvider</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token class-name static-context">ServiceProvider</span><span class="token operator">::</span><span class="token function">addProviderToBootstrapFile</span><span class="token punctuation">(</span><span class="token class-name static-context">Provider</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="队列" tabindex="-1"><a class="header-anchor" href="#队列"><span>队列</span></a></h3>
<h4 id="batchrepository-接口" tabindex="-1"><a class="header-anchor" href="#batchrepository-接口"><span><code v-pre>BatchRepository</code> 接口</span></a></h4>
<p><strong>影响可能性：非常低</strong></p>
<p><code v-pre>Illuminate\Bus\BatchRepository</code> 接口新增了一个 <code v-pre>rollBack</code> 方法。如果你在自己的包或应用程序中实现了这个接口，你应该在你的实现中添加这个方法：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">rollBack</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h4 id="数据库事务中的同步作业" tabindex="-1"><a class="header-anchor" href="#数据库事务中的同步作业"><span>数据库事务中的同步作业</span></a></h4>
<p><strong>影响可能性：非常低</strong></p>
<p>以前，同步作业（使用 <code v-pre>sync</code> 队列驱动的作业）会立即执行，无论队列连接的 <code v-pre>after_commit</code> 配置选项是否设置为 <code v-pre>true</code> 或是否调用了作业上的 <code v-pre>afterCommit</code> 方法。</p>
<p>在 Laravel 11 中，同步队列作业现在将遵守队列连接或作业的“提交后”配置。</p>
<h3 id="速率限制" tabindex="-1"><a class="header-anchor" href="#速率限制"><span>速率限制</span></a></h3>
<h4 id="每秒速率限制" tabindex="-1"><a class="header-anchor" href="#每秒速率限制"><span>每秒速率限制</span></a></h4>
<p><strong>影响可能性：中等</strong></p>
<p>Laravel 11 支持每秒速率限制，而不再局限于每分钟的粒度。与此变更相关，有多种可能的破坏性更改你应当了解。</p>
<p><code v-pre>GlobalLimit</code> 类的构造函数现在接受秒而不是分钟。这个类没有文档记录，通常不会被你的应用程序使用：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">new</span> <span class="token function">GlobalLimit</span><span class="token punctuation">(</span><span class="token variable">$attempts</span><span class="token punctuation">,</span> <span class="token number">2</span> <span class="token operator">*</span> <span class="token number">60</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p><code v-pre>Limit</code> 类的构造函数现在接受秒而不是分钟。所有文档记录的此类用法都限于静态构造函数，如 <code v-pre>Limit::perMinute</code> 和 <code v-pre>Limit::perSecond</code>。然而，如果你手动实例化这个类，你应该更新你的应用程序，以提供秒数给类的构造函数：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">new</span> <span class="token function">Limit</span><span class="token punctuation">(</span><span class="token variable">$key</span><span class="token punctuation">,</span> <span class="token variable">$attempts</span><span class="token punctuation">,</span> <span class="token number">2</span> <span class="token operator">*</span> <span class="token number">60</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p><code v-pre>Limit</code> 类的 <code v-pre>decayMinutes</code> 属性已更名为 <code v-pre>decaySeconds</code>，现在包含秒而不是分钟。</p>
<p><code v-pre>Illuminate\Queue\Middleware\ThrottlesExceptions</code> 和 <code v-pre>Illuminate\Queue\Middleware\ThrottlesExceptionsWithRedis</code> 类的构造函数现在接受秒而不是分钟：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">new</span> <span class="token function">ThrottlesExceptions</span><span class="token punctuation">(</span><span class="token variable">$attempts</span><span class="token punctuation">,</span> <span class="token number">2</span> <span class="token operator">*</span> <span class="token number">60</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">new</span> <span class="token class-name">ThrottlesExceptionsWithRedis</span><span class="token punctuation">(</span><span class="token variable">$attempts</span><span class="token punctuation">,</span> <span class="token number">2</span> <span class="token operator">*</span> <span class="token number">60</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="cashier-stripe" tabindex="-1"><a class="header-anchor" href="#cashier-stripe"><span>Cashier Stripe</span></a></h3>
<h4 id="更新-cashier-stripe" tabindex="-1"><a class="header-anchor" href="#更新-cashier-stripe"><span>更新 Cashier Stripe</span></a></h4>
<p><strong>影响可能性：高</strong></p>
<p>Laravel 11 不再支持 Cashier Stripe 14.x。因此，你应该在你的 <code v-pre>composer.json</code> 文件中更新你的应用程序的 Laravel Cashier Stripe 依赖到 <code v-pre>^15.0</code>。</p>
<p>Cashier Stripe 15.0 不再自动从其自己的迁移目录加载迁移。相反，你应该运行以下命令将 Cashier Stripe 的迁移发布到你的应用程序：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan vendor:publish <span class="token parameter variable">--tag</span><span class="token operator">=</span>cashier-migrations</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>请查阅完整的 <a href="https://github.com/laravel/cashier-stripe/blob/15.x/UPGRADE.md" target="_blank" rel="noopener noreferrer">Cashier Stripe 升级指南</a> 以了解更多破坏性变更。</p>
<h3 id="spark-stripe" tabindex="-1"><a class="header-anchor" href="#spark-stripe"><span>Spark (Stripe)</span></a></h3>
<h4 id="更新-spark-stripe" tabindex="-1"><a class="header-anchor" href="#更新-spark-stripe"><span>更新 Spark Stripe</span></a></h4>
<p><strong>影响可能性：高</strong></p>
<p>Laravel 11 不再支持 Laravel Spark Stripe 4.x。因此，你应该在你的 <code v-pre>composer.json</code> 文件中更新你的应用程序的 Laravel Spark Stripe 依赖到 <code v-pre>^5.0</code>。</p>
<p>Spark Stripe 5.0 不再自动从其自己的迁移目录加载迁移。相反，你应该运行以下命令将 Spark Stripe 的迁移发布到你的应用程序：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan vendor:publish <span class="token parameter variable">--tag</span><span class="token operator">=</span>spark-migrations</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>请查阅完整的 <a href="https://spark.laravel.com/docs/spark-stripe/upgrade.html" target="_blank" rel="noopener noreferrer">Spark Stripe 升级指南</a> 以了解更多破坏性变更。</p>
<h3 id="passport" tabindex="-1"><a class="header-anchor" href="#passport"><span>Passport</span></a></h3>
<h4 id="更新-passport" tabindex="-1"><a class="header-anchor" href="#更新-passport"><span>更新 Passport</span></a></h4>
<p><strong>影响可能性：高</strong></p>
<p>Laravel 11 不再支持 Laravel Passport 11.x。因此，你应该在你的 <code v-pre>composer.json</code> 文件中更新你的应用程序的 Laravel Passport 依赖到 <code v-pre>^12.0</code>。</p>
<p>Passport 12.0 不再自动从其自己的迁移目录加载迁移。相反，你应该运行以下命令将 Passport 的迁移发布到你的应用程序：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan vendor:publish <span class="token parameter variable">--tag</span><span class="token operator">=</span>passport-migrations</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>此外，默认情况下禁用了密码授权类型。你可以通过在你的应用程序的 <code v-pre>AppServiceProvider</code> 的 <code v-pre>boot</code> 方法中调用 <code v-pre>enablePasswordGrant</code> 方法来启用它：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">boot</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token class-name static-context">Passport</span><span class="token operator">::</span><span class="token function">enablePasswordGrant</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="sanctum" tabindex="-1"><a class="header-anchor" href="#sanctum"><span>Sanctum</span></a></h3>
<h4 id="更新-sanctum" tabindex="-1"><a class="header-anchor" href="#更新-sanctum"><span>更新 Sanctum</span></a></h4>
<p><strong>影响可能性：高</strong></p>
<p>Laravel 11 不再支持 Laravel Sanctum 3.x。因此，你应该在你的 <code v-pre>composer.json</code> 文件中更新你的应用程序的 Laravel Sanctum 依赖到 <code v-pre>^4.0</code>。</p>
<p>Sanctum 4.0 不再自动从其自己的迁移目录加载迁移。相反，你应该运行以下命令将 Sanctum 的迁移发布到你的应用程序：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan vendor:publish <span class="token parameter variable">--tag</span><span class="token operator">=</span>sanctum-migrations</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>然后，在你的应用程序的 <code v-pre>config/sanctum.php</code> 配置文件中，你应该将 <code v-pre>authenticate_session</code>、<code v-pre>encrypt_cookies</code> 和 <code v-pre>validate_csrf_token</code> 中间件的引用更新为以下内容：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'middleware'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'authenticate_session'</span> <span class="token operator">=></span> <span class="token class-name class-name-fully-qualified static-context">Laravel<span class="token punctuation">\</span>Sanctum<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Middleware<span class="token punctuation">\</span>AuthenticateSession</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'encrypt_cookies'</span> <span class="token operator">=></span> <span class="token class-name class-name-fully-qualified static-context">Illuminate<span class="token punctuation">\</span>Cookie<span class="token punctuation">\</span>Middleware<span class="token punctuation">\</span>EncryptCookies</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'validate_csfr_token'</span> <span class="token operator">=></span> <span class="token class-name class-name-fully-qualified static-context">Illuminate<span class="token punctuation">\</span>Foundation<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Middleware<span class="token punctuation">\</span>ValidateCsrfToken</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="telescope" tabindex="-1"><a class="header-anchor" href="#telescope"><span>Telescope</span></a></h3>
<h4 id="更新-telescope" tabindex="-1"><a class="header-anchor" href="#更新-telescope"><span>更新 Telescope</span></a></h4>
<p><strong>影响可能性：高</strong></p>
<p>Laravel 11 不再支持 Laravel Telescope 4.x。因此，你应该在你的 <code v-pre>composer.json</code> 文件中更新你的应用程序的 Laravel Telescope 依赖到 <code v-pre>^5.0</code>。</p>
<p>Telescope 5.0 不再自动从其自己的迁移目录加载迁移。相反，你应该运行以下命令将 Telescope 的迁移发布到你的应用程序：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan vendor:publish <span class="token parameter variable">--tag</span><span class="token operator">=</span>telescope-migrations</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="spatie-once-包" tabindex="-1"><a class="header-anchor" href="#spatie-once-包"><span>Spatie Once 包</span></a></h3>
<p><strong>影响可能性：中等</strong></p>
<p>Laravel 11 现在提供了自己的 <a href="https://learnku.com/docs/laravel/11.x/helpers#method-once" target="_blank" rel="noopener noreferrer"><code v-pre>once</code> 函数</a>，以确保给定的闭包只执行一次。因此，如果你的应用程序依赖于 <code v-pre>spatie/once</code> 包，你应该从你的应用程序的 <code v-pre>composer.json</code> 文件中移除它，以避免冲突。</p>
<h3 id="其他" tabindex="-1"><a class="header-anchor" href="#其他"><span>其他</span></a></h3>
<p>我们还鼓励你查看 <code v-pre>laravel/laravel</code> 的 <a href="https://github.com/laravel/laravel" target="_blank" rel="noopener noreferrer">GitHub 仓库</a>中的变更。虽然许多这些变更不是必需的，你可能希望将这些文件与你的应用程序保持同步。这些变更中的一些将在此升级指南中介绍，但其他一些，如配置文件或注释的变更，则不会。你可以使用 <a href="https://github.com/laravel/laravel/compare/10.x...11.x" target="_blank" rel="noopener noreferrer">GitHub 比较工具</a> 轻松查看变更，并选择对你而言重要的更新。</p>
<blockquote>
<p>本译文仅用于学习和交流目的，转载请务必注明文章译者、出处、和本文链接<br>
我们的翻译工作遵照 <a href="https://learnku.com/docs/guide/cc4.0/6589" target="_blank" rel="noopener noreferrer">CC 协议</a>，如果我们的工作有侵犯到您的权益，请及时联系我们。</p>
</blockquote>
<hr>
<blockquote>
<p>原文地址：<a href="https://learnku.com/docs/laravel/11.x/upgrademd/16645" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/11.x/up...</a></p>
<p>译文地址：<a href="https://learnku.com/docs/laravel/11.x/upgrademd/16645" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/11.x/up...</a></p>
</blockquote>
</div></template>


